const state = () => ({
  znxkInfo: {
    // 左上角选择省份是否需要调接口
    popupType: 'deafult',
    // 选择完省份是否需要清除已选数据
    needClear: false,
    // 对应省份科目列表
    subjectOptions: [],
    // 已选院校列表
    selectCollegeList: [],
    // 已选专业列表
    selectMarjorList: [],
    // 已选科目id
    sgId: [1, 2, 3],
    zySgID: [],
    yxSgID: [],
    // 筛选院校条件集合
    filterCollegeList: [],
    // 筛选专业条件集合
    filterMarjorList: [],
    currentCityeInfo: {
      provinceCode: '',
      year: '',
      xk_type: '',
      provinceName: '',
    },
    matchRateInfo: {
      percentCollegeMatch: '',
      percentMajorMatch: '',
      related: '',
    },
    isManualSelectZy: false,
    isManualSelectYx: false,
    isTableSelectZy: false,
    isTableSelectYx: false,
  },
});

// getters
const getters = {};

// actions
const actions = {
  changePopupType({ commit }, val) {
    commit('set_popupType', val);
  },
  changeNeedClear({ commit }, val) {
    commit('set_needClear', val);
  },
  changeSubjectOptions({ commit }, val) {
    commit('set_subjectOptions', val);
  },
  changeSelectCollegeList({ commit }, val) {
    commit('set_selectCollegeList', val);
  },
  changeSelectMarjorList({ commit }, val) {
    commit('set_selectMarjorList', val);
  },
  changeSgId(state, payload) {
    const { index, id } = payload;
    state.znxkInfo.sgId[index] = id;
  },
  changeZySgId({ state }, val) {
    state.znxkInfo.zySgID = [...val];
  },
  changeYxSgId({ state }, val) {
    state.znxkInfo.yxSgID = [...val];
  },
  changeFilterCollegeList({ commit }, val) {
    commit('set_filterCollegeList', val);
  },
  changeFilterMarjorList({ commit }, val) {
    commit('set_filterMarjorList', val);
  },
  changeCurrentCityeInfo({ commit }, val) {
    commit('set_currentCityeInfo', { ...val });
  },
  changeMatchRateInfo({ commit }, val) {
    commit('set_matchRateInfo', { ...val });
  },
  updateManualSelect({ commit }, value) {
    commit('setManualSelect', { ...value });
  },
  updateTableSelect({ commit }, value) {
    commit('setTableSelect', { ...value });
  },
};

// mutations
const mutations = {
  setManualSelect(state, value) {
    if (value.isMajor) {
      state.znxkInfo.isManualSelectZy = value.flag;
    } else {
      state.znxkInfo.isManualSelectYx = value.flag;
    }
  },
  setTableSelect(state, value) {
    if (value.isMajor) {
      state.znxkInfo.isTableSelectZy = value.flag;
    } else {
      state.znxkInfo.isTableSelectYx = value.flag;
    }
  },
  set_popupType: (state, val) => {
    state.znxkInfo.popupType = val;
  },
  set_needClear: (state, val) => {
    state.znxkInfo.needClear = val;
  },
  set_subjectOptions: (state, val) => {
    state.znxkInfo.subjectOptions = val;
  },
  set_selectCollegeList: (state, val) => {
    state.znxkInfo.selectCollegeList = val;
  },
  set_selectMarjorList: (state, val) => {
    state.znxkInfo.selectMarjorList = val;
  },
  set_sgId(state, payload) {
    const { index, id } = payload;
    state.znxkInfo.sgId[index] = id;
  },
  set_zysgId(state, payload) {
    const { index, id } = payload;
    state.znxkInfo.zySgID[index] = id;
  },
  set_yxsgId(state, payload) {
    const { index, id } = payload;
    state.znxkInfo.yxSgID[index] = id;
  },
  set_filterCollegeList: (state, val) => {
    state.znxkInfo.filterCollegeList = val;
  },
  set_filterMarjorList: (state, val) => {
    state.znxkInfo.filterMarjorList = val;
  },
  set_currentCityeInfo: (state, val) => {
    state.znxkInfo.currentCityeInfo = { ...val };
  },
  set_matchRateInfo: (state, val) => {
    state.znxkInfo.matchRateInfo = { ...val };
  },
};

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations,
};
